<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>

  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <!--js引入要放在最上面-->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>

  <!--css的引入要放在js的下面-->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
  <script src="js/utils.js"></script>
  <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
  <style>
    #div {
      width: 80%;
      margin: 100px auto 0;
    }
  </style>
</head>
<body>

<div>
  <div class="form-group">
    <label for="username">用户名</label>
    <input type="text" class="form-control" id="username" placeholder="用户名">
  </div>
  <div class="form-group">
    <label for="password">密码</label>
    <input type="password" class="form-control" id="password" placeholder="密码">
  </div>
  <button id="login" class="btn btn-success">登录</button>
</div>



<script>
  login.onclick = async  function () {
    if ((!username.value.trim())||(!password.value.trim())) {
      alert('请输入完整信息');
      return;
    }

    let res = await postRequest('/login', {name: username.value, pwd: password.value});
    localStorage.setItem('token', res.token);
    location.href = 'home.html';

  };

</script>

</body>
</html>
